var app = new Vue({
    el: '#app',
    data: {
        self: this,
        columns: [
            {
                title: 'ID',
                key: 'id',
                width: 80
            },
            {
                title: '键值',
                key: 'key',
                width: 200
            },
            {
                title: '键名',
                key: 'value',
                width: 250
            }, {
                title: '添加时间',
                key: 'created_at',
                width: 200
            },
            {
                title: '操作',
                key: 'action',
                align: 'center',
                render (row, column, index) {
                    return `<i-button type="primary" size="small" v-on:click="show(${index})">编辑</i-button> <i-button type="error" size="small" @click="remove(${index})">删除</i-button>`;
                }
            }
        ],
        settingList: [],
        //分页
        currentPage: 1,
        totalPage: 1,
        //搜索
        searchForm: {
            'key': '',
            'value': ''
        },
        //弹窗
        deleteDilog: false,
        modal_loading: false,
    },
    methods: {
        //点击分页
        handleCurrentChange: function (val) {
            //this.currentPage = val;
            //console.log('当前页: ' + val);
            this.getSettingList(val, this.searchForm);
        },
        //搜索
        handSearch: function () {
            this.getSettingList(1, this.searchForm);
        },
        //获取会员列表
        getSettingList: function (currentPage, formData) {
            $.ajax({
                url: '/admin/setting/list',
                dataType: 'json',
                type: 'POST',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                },
                data: {
                    page: currentPage,
                    key: formData ? formData.key : '',
                    value: formData ? formData.value : ''
                },
                success: function (data, textStatus, jqXHR) {
                    //console.log(data);
                    //填充数据
                    app.settingList = data.datas.data;
                    //填充分页
                    app.currentPage = data.datas.current_page;
                    app.totalPage = data.datas.total;
                },
                error: function (xhr, textStatus) {
                    console.log('错误');
                    console.log(xhr);
                    console.log(textStatus);
                }
            });
        }
    }
});
app.getSettingList(1);
